package futbol.tacticas.concursantes.qualitycode.common;

import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import futbol.tacticas.concursantes.qualitycode.QCodeTactica;
import futbol.tacticas.concursantes.qualitycode.ctrlteam.QCtrlPlayer;

public abstract class QTeam<T extends QPlayer>
{
  protected final List<T> players = new ArrayList<T>(QCodeTactica.TEAM_SIZE);
  private final String ID;
  private int goals = 0;
  
  public QTeam(String ID)
  {
    this.ID = ID;
  }
 
  public void reset()
  {
    for (QPlayer player : players)
      player.reset();
  }
  
  public void incGoals()
  {
    goals++;
  }

  public int getGoals()
  {
    return goals;
  }
  
  public List<T> getPlayers()
  {
    return Collections.unmodifiableList(players);
  }
  
  public void updatePos(Point[] newPos)
  {
    for (int i = 0; i < players.size(); i++)
      players.get(i).updatePos(newPos[i]);     
  }

  public T getPlayer(int n)
  {
    return players.get(n);
  }

  public String toString()
  {
    final StringBuffer str = new StringBuffer("-Team " + ID + "\n");
    for (int i = 0; i < players.size(); i++)
      str.append(String.format("    %s\n", players.get(i).toString()));
    
    return str.toString();
  }
  
  public void pintar(boolean over, Graphics gdb)
  {
    //for (T player : players)
      //player.pintar(over, gdb);
  }
  
  public List<T> cercania(QPlayer player)
  {
    final List<T> cercania = cercania(player.getPos());
    cercania.remove(player);
    return cercania;
  }

  public List<T> cercania(Point p)
  {
    final List<T> cercania = QUtils.cercania(players, p);
    return cercania;
  }

}





























